package com.infinit.easyreader.adpter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioButton;
import android.widget.TextView;

import com.infinit.easyreader.R;

import java.util.List;

/**
 * 类：com.infinit.easyreader.adpter V[1.0.0]
 * 作用：
 * Created by rzy on 2016/5/20.
 */
public class FontAdapter extends BaseAdapter<String> {
    private int checkedPosition = 0;

    public FontAdapter(List<String> dataList, Context context) {
        super(dataList, context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        String fontName = getDataList().get(position);
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = getInflater().inflate(R.layout.font_content, null);
            viewHolder = new ViewHolder();
            viewHolder.rbChecked = (RadioButton) convertView.findViewById(R.id.rbFontChecked);
            viewHolder.tvFontName = (TextView) convertView.findViewById(R.id.tvFontName);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.rbChecked.setVisibility(View.GONE);
        if (position == checkedPosition) {
            viewHolder.rbChecked.setVisibility(View.VISIBLE);
        }
        viewHolder.tvFontName.setText(fontName);
        return convertView;
    }


    public void setCheckedPosition(int checkedPosition) {
        this.checkedPosition = checkedPosition;
    }

    private class ViewHolder {
        TextView tvFontName;
        RadioButton rbChecked;
    }
}
